package org.dormi.learn.product.domain.product.entity;

import lombok.Getter;
import lombok.Setter;
import org.dormi.learn.primitive.Currency;
import org.dormi.learn.primitive.Money;
import org.dormi.learn.utils.Assert;
import org.dormi.learn.utils.TrackingUtils;

import java.util.Map;

/**
 * add description here
 *
 * @author : dormi330
 * @version : 1.0
 */
@Getter
@Setter
public class ProductVariant {

    private Long id;
    private Map<String, String> attributes;
    private Money salesPrice;
    private Boolean canBeSold = false;
    private Boolean canBePurchased = false;
    private Money cost = new Money("0.00", Currency.RMB);
    private String name;
    private String materialCode;

    /** 完整性校验 */
    public void checkIntegrity() {
        TrackingUtils.debugTrace();

        // attributes 不能为空
        Assert.isTrue(hasAttribute(), "不能为空, attributes");

        // not null check
        Assert.isNotNull(salesPrice, "不能为null: salesPrice");
        Assert.isNotNull(name, "不能为null: name");
        Assert.isNotNull(materialCode, "不能为null: materialCode");

    }

    /** 是否单规格 */
    private boolean hasAttribute() {
        return attributes != null && attributes.size() > 0;
    }
}
